<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html lang="en">
<head>
<title>采购合同列表</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />

<link rel="icon" href="favicon.ico" type="image/x-icon" />
<!-- END META SECTION -->

<!-- CSS INCLUDE -->        
      
<link rel="stylesheet" href="${ctx}/rs/css/bootstrap-table.css" />
<link rel="stylesheet" href="${ctx}/rs/css/main.css" />
<link id="theme" rel="stylesheet" href="${ctx}/rs/joli/css/theme-default.css" />
<style type="text/css">
.table th, .table td { 
text-align: center;
vertical-align: middle!important;
}
.tableover{ white-space: nowrap; overflow: hidden; overflow-x: scroll; -webkit-backface-visibility: hidden; -webkit-overflow-scrolling: touch;}
.w100{
    width:100px;
    white-space: normal;
}
.w200{
    width:200px;
    white-space: normal;
    }
.wt{
    width: 2600px !important;
}
</style>
<!-- EOF CSS INCLUDE -->        
</head>
<body >

     <!-- START PAGE CONTAINER -->
      <div class="page-container">
        <!-- 引入左菜单部分 -->
          <jsp:include page="../joli/menu.jsp"></jsp:include>
          
          <!-- START PAGE CONTENT -->
          <div class="page-content">
              <jsp:include page="../joli/top.jsp"></jsp:include>
              
              <!-- START BREADCRUMB -->
              <ul class="breadcrumb">
                  <li><a href="#">合同管理</a></li>                    
                  <li class="active">合同统计</li>
                  <li class="active">采购合同</li>
              </ul>
              <!-- END BREADCRUMB -->   
              
              
              <!-- PAGE CONTENT WRAPPER -->
              <div class="page-content-wrap">
               <input type ="hidden" id = "contractStatus" name = "contractStatus" value = "${contractStatus}">
                <input type ="hidden" id = "endTime" name = "endTime" value = "${endTime}">
                <input type ="hidden" id = "beginTime" name = "beginTime" value = "${beginTime}">
                <input type ="hidden" id = "type" name = "type" value = "${type}">
                 <input type ="hidden" id="order" name = "order" >
                <div class="row">
                    <div class="col-xs-12">
                        <div id="toolbar">
                          <button class="btn btn-info srt-btn btn-sm icon-adds" onclick="refresh(0)">默认排序</button>
                          <button class="btn btn-info srt-btn btn-sm icon-adds" onclick="refresh(1)">升序排序</button>
                          <button class="btn btn-info srt-btn btn-sm icon-adds" onclick="refresh(2)">降序排序</button>
                          <button class="btn btn-info srt-btn btn-sm icon-adds" onclick="excel()">导出excel</button>
                          <button class="btn btn-info srt-btn btn-sm icon-adds" onclick="gobak()">返回</button>
                        </div>
                        <div class = "tableover">
                        <table id="table" cellpadding="0" cellspacing="0" data-toggle="table" data-toolbar="#toolbar" class="wt"
                            data-url="${ctx}/contract/listCountInfo.htm"
                            data-cache="false"
                            data-pagination="true" 
                            data-side-pagination="server"
                            data-page-list="[10, 20, 50, 100]"
                            data-page-size="20"  
                            data-query-params="queryParams"
                            >
                            <thead>
                                 <tr class="tab-th">
                                     <th data-field="sellCode" class="w100">销售合同编号</th>
                                     <th data-field="buyCode" class="w100">采购合同编号</th>
                                     <th data-field="extendMedia" class="w100">推广媒体</th>
                                     <th data-field="advName" class="w100">广告客户</th>
                                     <th data-field="advProduct" class="w100">广告产品</th>
                                     <th data-field="sumSignMoney" class="w100" data-formatter="moneyFormatter">签约总金额</th>
                                     <th data-field="copywithMoney" class="w100" data-formatter="moneyFormatter">应付总金额</th>
                                     <th data-field="addupMoney" class="w100" data-formatter="moneyFormatter">累计已付金额</th>
                                     <th data-field="nonPayMoney" class="w100" data-formatter="moneyFormatter">未付金额</th>
                                     <th data-field="signTime" class="w100" data-formatter="signtimeFormatter">签约日期</th>
                                     <th data-field="throwTime" class="w100" data-formatter="timeFormatter">投放期限</th>
                                     <th data-field="contractStatus" class="w100" data-formatter="statusFormatter">合同状态</th>
                                     <th data-field="payWay" class="w100" data-formatter="paywayFormatter">结算方式</th>
                                     <th data-field="salesman" class="w100" >业务员</th>
                                     <th data-field="action" class="w100" data-formatter="actionFormatter">扫描件</th>
                                     <th data-field="remarks" class="w200" >备注</th>
                                 </tr>
                            </thead>
                        </table>
                        </div>
                </div>
              </div>  
         </div>
     </div>
          <!-- 引入所有joli的脚本 -->
    <jsp:include page="../joli/scripts.jsp"></jsp:include>
    <!-- 引入页面需要的脚本 -->
    <script type="text/javascript" src="${ctx}/rs/js/qiao.js"></script>
    <script type="text/javascript" src="${ctx}/rs/js/bootstrapQ.min.js"></script>
    <script src="${ctx}/rs/js/bootstrap-table.js"></script>
    <script src="${ctx}/rs/js/bootstrap-table-zh-CN.js"></script>
    <script src="${ctx}/rs/js/jquery.formatDate.js"></script>
    <script src="${ctx}/rs/js/jquery.form.js" type="text/javascript"></script>
    <script src="${ctx}/rs/js/my97DatePicker/WdatePicker.js"></script>
    <script type="text/javascript" src="${ctx}/rs/js/session-out-error.js"></script>
    <script type="text/javascript">
    activeMenu($("#menu_contract_2"));
    var $table = $('#table');
    
    $table.on('click-row.bs.table', function (e, row, $element) {
          $table.bootstrapTable('uncheckAll');
          $table.bootstrapTable('check', $element.index());
    });
    
    $table.bootstrapTable({
        height: getHeight()
    });
      
    //获取分辨率高度
      function getHeight() {
          return window.screen.height - 308;
      }
      
      $(window).resize(function () {
      $table.bootstrapTable('resetView',{height: getHeight()});
    });
      
    //初始化刷新
    var order;
   function refresh(order1){
	  $("#order").val(order1);
    	order= order1;
        var contractStatus = $("#contractStatus").val();
        var type = $("#type").val();
        var beginTime = $("#beginTime").val();
        var endTime = $("#endTime").val();
        var pageSize = $table.bootstrapTable('getOptions').pageSize;
        pageIndex=0;
        $table.bootstrapTable('refresh', {
            silent: true,
            cache : false,
            url: '${ctx}/contract/listCountInfo.htm',
            query: {
            	order:order,
            	type:type,
                contractStatus:contractStatus,
                startTime:beginTime,
                endTime:endTime,
                pageIndex : pageIndex,
                pageSize : pageSize
            }
        });
        $table.bootstrapTable('selectPage', 20);
    }
   function queryParams(params) {
       var contractStatus = $("#contractStatus").val();
       var beginTime = $("#beginTime").val();
       var endTime = $("#endTime").val();
       var type = $("#type").val();
        order = $("#order").val();
       return {
    	   order:order,
           contractStatus:contractStatus,
           type:type,
           startTime:beginTime,
           endTime:endTime,
           pageIndex : params.offset,
           pageSize : params.limit
       };
   }
    function signtimeFormatter(value, row, index){
         if(value){
             return $.formatDate("yyyy-MM-dd", new Date(value));
         }
         return "--";
    }
    function timeFormatter(value, row, index){
        if(value){
        	var a = value.split("~");
            
            return a[0]+"<br/>"+"~"+a[1];
        }
        return "--";
   }
    function actionFormatter(value, row, index){
        var retbak="";
        retbak='<a class="mr15" href="javascript:adduplist('+row.id+')">查看扫描件</a>';
        return retbak;
    }
    function statusFormatter(value, row, index){
        var retbak="";
        switch(row.contractStatus){
        case 0:
            retbak="<sapn class='label label-success'>未启动</span>";
            break;
        case 1:
            retbak="<span class='label label-info'>执行中</span>";
            break;
        case 2:
            retbak="<span class='label label-danger'>结束</span>";
            break;
        }
        return retbak;
    }
    function moneyFormatter(value, row, index){
    	if(value == null){
            value="0.00";
        }
        return "￥"+value.toFixed(2);
    }
    function paywayFormatter(value, row, index){
        var bak = '';
	    	if(value == 0){
	    		bak = '预付';
	    	}else{
	    		bak = '月付';
	    	}
    	return bak;
    }
    
    
    function add() {
        var pageNumber = $table.bootstrapTable('getOptions').pageNumber;
        var pageIndex = pageNumber - 1;
        bootstrapQ.dialog({
            url : '${ctx}/contract/buyadd.htm',
            title : '添加合同',
            width : "650px",
            scrolly : "true",
            close : 'true',
            hidebtn : 'true'
        },function(){
            //回调触发关闭窗口
            $("#bsmodal").modal("hide");
            refresh();
        });
    };
    
    
  //已付款记录
    function adduplist(id) {
    	bootstrapQ.dialog({
                 url : "${ctx}/contract/photolist.htm?id="+ id,
                 title : "扫描件",
                 width: '650px',
                 close : 'true',
                 hidebtn : 'true'
             },function(){
                 //回调触发关闭窗口
                 $("#bsmodal").modal("hide");
             });
     }
  
   //导出
   function excel() {
       var num=0;
       $('#table').find('tbody tr').each(function(i){
           if(i==0){
               if($(this).find("td").eq(0).html()=="没有找到匹配的记录"){
                   num++;
               }
           }
       });
       if(num>0){
           bootstrapQ.alert("对不起，无数据！");
           return;
       }else{
           bootstrapQ.confirm('确定要导出吗？',function(){
        	   var beginTime = $("#beginTime").val();
               var endTime = $("#endTime").val();
               var contractStatus = $("#contractStatus").val();
               var type = $("#type").val();
             if(order == "" ||order  == null){
            	 order = "";
             }
               order = order;
               window.location.href= "${ctx}/contract/exportExcelsell.htm?beginTime="+beginTime+"&endTime="+endTime+"&contractStatus="+contractStatus+"&type="+type+"&order="+order;
           })
       }
       
   }
   
   function gobak(){
	   window.location.href = "${ctx}/send.htm?page=contract/countList";
   }
    </script>
  </body >
</html>
